﻿@model RH.Web.ViewModels.UtilityModels.ListConfig
@using RH.Common.Extensions;
@using RH.Common.DB;
@using RH.Web.ViewModels;
@using RH.Web.ViewModels.UtilityModels;          
@using RH.Web.Utility;
@{
    String pageTitle = "My Favourite Properties";

    ViewBag.Title = Html.GetPageTitle(pageTitle);
    ListConfig config = ListConfigBuilder.Build("User Favorites{Thumbnail|Name|Added On}", Model.DataSource, String.Empty);
    ListConfig.Map(config, Model);
    Column thumb = Model.Columns.FirstOrDefault(P => P.Name == "Thumbnail");
    thumb.Method = P =>
    {
        int id = NullHandler.GetInt(P["ID"]);
        return MvcHtmlString.Create(String.Format("<img class=\"img-thumbnail\" src=\"{0}\"/>", ImageManager.GetProductImageUrl(NullHandler.GetString(P["Thumbnail"]), id)));
    };
    Column name = Model.Columns.FirstOrDefault(P => P.Name == "Name");
    name.Method = P =>
    {
        return Html.ProductDetailsLink(NullHandler.GetInt(P["ID"]), NullHandler.GetString(P["ProductUrl"]), NullHandler.GetString(P["Name"]).HtmlEncode());
    };

    Column deleteColumn = new Column("Delete",
    P =>
    {
        int id = RH.Common.DB.NullHandler.GetInt(P["FavoriteID"]);
        return MvcHtmlString.Create(String.Format("<a class=\"btn btn-warning btn-sm\" href=\"javascript:void(0);\" onclick=\"DeleteConfirm({0}, this, _DelCnfMsg);\"><i class=\"glyphicon glyphicon-remove\"></i> </a>", id));
    });
    Model.Columns.Add(deleteColumn);
    ViewData[AppConstants.ViewDataKeys.SELECTED_MENU] = SiteUserMenu.Favorites;
}

<div class="rh-page-heading">
    <h1>@pageTitle</h1>
    <div>
        List of your favorite properties. You can remove them by clicking on the delete button.
    </div>
</div>
<div class="rh-page-content">
    <div class="panel panel-success">
        <div class="panel-heading">
            <div class="pull-left"><h4>Favorite Properties</h4></div>
            <div class="pull-right"></div>
            <div class="clearfix"></div>
        </div>
        <div class="panel-body">
            @Html.Partial("_DataTableList", Model)
        </div>
    </div>
    @if (Model.Pager != null)
    {
        @Html.Partial("_Pager", Model.Pager)
    }
</div>
@{
    ModalViewModel deleteConfirm = new ModalViewModel("deleteConfirm", "Confirm", String.Format("DeleteEntity('{0}', 'Property deleted Successfully from your favorite list.', 'Sorry! we were not able to delete this property from your favorite list.');", Url.SiteUserUrl("Delete", "Favorites")));
    deleteConfirm.CloseButton = "No";
    deleteConfirm.SaveButton = "Yes";
}
@Html.Partial("_Modal", deleteConfirm)

@section JavaScriptPlaceHolder{
    <script language="javascript" type="text/javascript">
        var _DelCnfMsg = 'Are your sure, you want to delete this property from your favorite list?';
    </script>
}   